package com.reflect;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-12-12
 * Time: 9:09
 */
//public class Test1 {
//    public static void main(String[] args) throws ClassNotFoundException {
//        //对象.getClass();
//        Student s = new Student("张三", 200);
//        Class c1 = s.getClass();
//        System.out.println(c1);
//
//          //类名.class
//        Class c2 = Student.class;
//        System.out.println(c2);
//
//        //Class.forName(String str);
//        Class c3 = Class.forName("com.reflect.Student");
//        System.out.println(c3);
//    }
//}

public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException {
        //获取Student类的Class对象的类
        Class c = Student.class;

        //获取包名
        Package packageName = c.getPackage();
        String name = packageName.getName();
        System.out.println(name);

        //获取类名
        String name1 = c.getName();
        System.out.println(name1);

        //获取父类的类名
        String s = c.getSuperclass().getName();
        System.out.println(s);

        //获取实现的接口
        Class[] interfaces = c.getInterfaces();
        for (Class anInterface : interfaces) {
            String name2 = anInterface.getName();
            System.out.println(name2);
        }
    }
}